package net.projects.pro2_atm;

import org.apache.log4j.Logger;

import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.UnknownHostException;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.Executors;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

public class BankServer {
   static Logger log=Logger.getLogger(BankServer.class.getName());
    public static void main(String[] args) {
        ThreadPoolExecutor pool=new ThreadPoolExecutor(
                10,
                10,
                10,
                TimeUnit.SECONDS,
                new ArrayBlockingQueue<>(10),
                Executors.defaultThreadFactory(),
                new ThreadPoolExecutor.AbortPolicy()
        );
        Bank b=new Bank();
        try {
            ServerSocket s=new ServerSocket(12000);
            while (true){
                Socket socket=s.accept();
                log.info(socket.getRemoteSocketAddress()+"连接成功");

                pool.execute(new BankTask(socket,b));

            }

        } catch (UnknownHostException e) {
            throw new RuntimeException(e);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
